<template>
  <div></div>
</template>
<script>
export default {
  created() {
    // 获取侧边栏菜单
    const menus = this.$store.getters.sidebarRouters || []
  
    // 递归找到第一个可访问的菜单
    function findFirstMenu(menus) {
      debugger
      for (const item of menus) {
        if (item.hidden || (item.meta && item.meta.hidden)) continue
        if (item.children && item.children.length) {
          const child = findFirstMenu(item.children)
          child.path = item.path +'/'+ child.path
          if (child) return child
        } else if (item.path && item.path !== '/' && item.path !== '/index') {
          return item
        }
      }
      return null
    }
    const firstMenu = findFirstMenu(menus)
    console.log(firstMenu)
    if (firstMenu) {
      this.$router.replace(firstMenu.path)
    } else {
      this.$router.replace('/404')
    }
  }
}
</script> 